<%@ Page Language="C#" AutoEventWireup="false" CodeBehind="WrapServerObjectBrowser.aspx.cs" Inherits="EPiServer.Research.TinyMCEAdapter.WrapServerObjectBrowser"  %>
<%@ Register TagPrefix="EPiServerUI" Namespace="EPiServer.UI.WebControls" Assembly="EPiServer.UI" %>

<asp:Content ID="Content1" ContentPlaceHolderID="HeaderContentRegion" runat="server">  
	<link href="<%=EPiServer.Configuration.Settings.Instance.SiteUrl%>App_Themes/Default/Styles/system.css" type="text/css" rel="stylesheet"/>
	<link href="<%=EPiServer.Configuration.Settings.Instance.SiteUrl%>App_Themes/Default/Styles/ToolButton.css" type="text/css" rel="stylesheet"/>
    
    <script type="text/javascript" src="<%= EPiServer.UriSupport.ResolveUrlFromUIBySettings("Javascript/system.js") %>"></script>
    <script type="text/javascript" src="<%=EPiServer.Configuration.Settings.Instance.SiteUrl%>/EPiServer.Research.Wiki/tiny_mce3211/tiny_mce_popup.js"></script>
       <script type="text/javascript" src="<%=EPiServer.Configuration.Settings.Instance.SiteUrl%>/EPiServer.Research.Wiki/tiny_mce3211/ajaxcall.js"></script>
    <script type="text/javascript">
        
      
        // used by clientscriptcode in EPiServer FileManagerBrowser and PageBrowser
        window.EPiOpenedDialog = new EPi.Dialog(enddialog, null, window.document);    
    
        // same callback used by FileManagerBrowser and PageBrowser
        function enddialog(returnValue, contextArguments)
        {
           
            if( returnValue )
            {
                if( returnValue==-1 )
                    returnValue = '';
                 var win = tinyMCEPopup.getWindowArg("window");    
                // special care has to be taken if we got return from PageBrowser (returnValue==true), 
                // as it has set the selected PageID in the PageUrlValue textbox. We need to roundtrip
                // to resolve this id into a relative url, which we then return to Tiny             
                if( returnValue==true )
                {
                      var pageId = document.getElementById('<%= PageUrlValue.ClientID %>').value;
                     
                    
                    if(!pageId)
                    {
                       win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = '';
                       tinyMCEPopup.close();
                    }
                    else
                    {
                    
                       var url = ResolveToLink(document.getElementById('<%= PageUrlValue.ClientID %>').value, '<%=EPiServer.Configuration.Settings.Instance.SiteUrl%>');
                     
                       win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = url;
                       tinyMCEPopup.close();
                    }
                }    
                else
                {
           
                  win.document.getElementById(tinyMCEPopup.getWindowArg("input")).value = returnValue;
                  tinyMCEPopup.close();
                 
                }
            }
            else tinyMCEPopup.close();
        }
            
        function pageFrame_loaded()
        {
            // PageBrowser is a little inconsistent regarding how its handling dialogs.
            // this will most likely be changed in upcoming builds, so this code might
            // have to be removed / altered.
            var o = document.getElementById('SelectPageFrame');
       
            // IE

            o.contentWindow.dialogArguments = window.document;
            o.contentWindow.EPiDialog = window.EPiOpenedDialog;
           
           o.contentWindow.setEnabledStateOfSelfButton();

        }
        
    </script>

</asp:Content>

<asp:Content ContentPlaceHolderID="FullRegion" runat="server">

    <input type="hidden" id="dummyinfo" />
    <input type="hidden" id="disablePageBrowserSelfLinkButton" value="true" />
    <asp:TextBox style="display:none;" id="PageUrlValue" runat="server" enableviewstate="true" AutoPostBack="false" />
    
    <EPiServerUI:TabStrip id="actionTab" runat="server" AutoPostBack="true" TargetID="tabView">
        
        <EPiServerUI:Tab Text="Page" runat="server" id="TabSelectPage"/>
        <EPiServerUI:Tab Text="File" runat="server" id="TabSelectFile"  />
    </EPiServerUI:TabStrip>

    <asp:Panel ID="tabView" runat="server"> 
        <asp:Panel ID="SelectPage" runat="server">
            <iframe id="SelectPageFrame" src="<%= EPiServer.UriSupport.ResolveUrlFromUIBySettings("Edit/PageBrowser.aspx") + "?id=&info=dummyinfo&value=" + PageUrlValue.ClientID %>" onload="pageFrame_loaded()" style="height:550px; width: 500px" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" ></iframe>
        </asp:Panel>
         <asp:Panel ID="SelectFile" runat="server">
            <iframe id="SelectFileFrame" src="<%= EPiServer.UriSupport.ResolveUrlFromUIBySettings("Edit/FileManagerBrowser.aspx") %>" style="height:600px; width: 500px" scrolling="no" frameborder="0" marginheight="0" marginwidth="0" ></iframe>
        </asp:Panel>
    </asp:Panel>
    
</asp:Content>